package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.User;
import service.UserService;

/**
 * Servlet implementation class JudgeLogin
 */
@WebServlet("/JudgeLogin")
public class JudgeLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserService us;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public JudgeLogin() {
        super();
        // TODO Auto-generated constructor stub
        us=new UserService();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		User u=new User();
		u.setName(username);u.setPassword(password);
		boolean t=us.allowLogin(u);
		if(t){
			response.sendRedirect("menu.jsp");
		}
		else{
			response.sendRedirect("login.jsp");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
